#x,n,

GroupData<-function(x,n){
  ##数组长度
  m<-length(x)
  if((n-m%%n)%%n < ceiling(m/n)){
    x<-c(x,rep(NA,(n-m%%n)%%n))
  }else{
    for(i in (m%%n+1):n){
      if(i == n){
        x<-c(x[1:(ceiling(m/n)*i-1)],NA)
      }else{
        x<-c(x[1:(ceiling(m/n)*i-1)],NA,x[(ceiling(m/n)*i):length(x)])
      }
    }
  }
  group<-matrix(x,nrow=n,byrow=T)
  return(group)
}
getScatterPointX <- function(x){
  len <- length(x)
  temp <- c()
  for(i in 1:len){
    temp <- append(temp,rep(i,x[i]))
  }
  return (temp)
}

library(moments)
if (is.null(n) || n == 0) {
    n <- ceiling(sqrt(length(x)))
}

if (is.null(bitNum) || bitNum <= 0) {
    bitNum <- 6
}

#普通值
avgValue <- mean(x)
minValue <- min(x)
maxValue <- max(x)
stdevValue <- sd(x)
rangeValue <- max(x) - min(x)
kurtosisValue <- kurtosis(x)
skewnessValue <- skewness(x)

cl <- c(-3, -2, -1, 0, 1, 2, 3)
CL <- avgValue + cl * stdevValue

#ScatterGroupLen <- ceiling(length(x)/n)
#xNa <- c(x, rep(NA, ScatterGroupLen * n - length(x)))
#xM <- matrix(xNa, n, ScatterGroupLen, byrow = T)
xM <- GroupData(x,n)
ScatterGroupLen <- ncol(xM)


ScatterPointX <- getScatterPointX(rowSums(!is.na(xM)))
ScatterPointY <- x

ScatterLineY <- apply(xM, 1, mean, na.rm=T)
ScatterLineX <- c(1:n)

CL <- round(CL, bitNum)
